package com.lebang.controller.api;

import com.lebang.model.RequestUserInfo;
import com.lebang.service.DataCollectService;
import com.lebangweb.common.TextUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/data")
public class DataCollectApi {


    @Autowired
    private DataCollectService dataCollectService;

    @PostMapping("/collect")
    public JsonData collect(HttpServletRequest request, String appName,String appPkg,String targetUrl,String json) {
        if(TextUtil.isEmpty(appName,appPkg,targetUrl,json)){
            return Callback.fail("201", "参数为空", null);
        }
        RequestUserInfo requestUserInfo = new RequestUserInfo(request);
        if(dataCollectService.collect(requestUserInfo.getAppId(),appName,appPkg,targetUrl,json)){
            return Callback.success("200", "收集成功", null);
        }
        return Callback.fail("202", "收集失败", null);

    }

}
